#ifndef XPMEDITOR_H
#define XPMEDITOR_H

#include <editorbase.h>
#include <projectfile.h>
#include <wx/bitmap.h>
#include <wx/sizer.h>
#include <wx/scrolwin.h>
#include <vector>
#include <set>

#include "XPMEditorPanel.h"

class XPMEditorPanel;
class XPMEditorBase;

class XPMEditorBase: public EditorBase {
  public:
    XPMEditorBase( wxWindow* parent, const wxString& title, wxImage *img, wxString sFileName );
    ~XPMEditorBase();
    static bool IsImgEditor( EditorBase* editor );
    static void CloseAllEditors( void );
    void SetPanel( wxPanel *Panel );
    wxPanel* GetPanel( void );

    //Save, Close, Readonly, is modified
    virtual bool GetModified( void ) const;
    virtual void SetModified( bool bModified );
    void UpdateModified( void );
    void SetReadOnly( bool bReadOnly );
    bool GetReadOnly( void ) const;
    bool IsReadOnly( void ) const;
    bool Save( void );
    bool SaveAs( void );
    bool Close( void );
    void SetProjectFile( ProjectFile* project_file, bool preserve_modified = false );
    void NotifyPlugins( wxEventType type, int intArg = 0, const wxString& strArg = wxEmptyString,
                        int xArg = 0, int yArg = 0 );

    bool CanUndo( void ) const;
    bool CanRedo( void ) const;
    void ClearUndoBuffer( void );
    void ClearRedoBuffer( void );
    bool AddUndo( wxBitmap *bm );
    bool AddRedo( wxBitmap *bm );
    bool AddUndo( wxImage *img );
    bool AddRedo( wxImage *img );
    bool AddUndo( void );
    bool AddRedo( void );
    void Undo( void );
    void Redo( void );
    bool CanCopy( void ) const;
    bool CanCut( void ) const;
    bool CanPaste( void ) const;
    void Cut( void );
    void Copy( void );
    void Paste( void );
    bool HasSelection( void ) const;
    void ClearSelection( void );
    void GetBoundingRect( wxRect *r );

    //image access
    wxImage GetImage( void );
    void SetImage( wxImage *img );

    //configuration
    void UpdateConfiguration( void );

  private:
    wxScrolledWindow* GetDrawCanvas( void );
    bool m_bModified;
    bool m_bReadOnly;
    bool m_bIsFileNameOK;
    XPMEditorPanel *m_DrawArea;
    ProjectFile* m_pProjectFile;
    void OnResize( wxSizeEvent& event );
    typedef std::set< EditorBase* > EditorsSet;
    static EditorsSet m_AllEditors;
};

#endif
